package com.googlecode.garbagecan.simonstudy;

import org.javasimon.SimonManager;
import org.javasimon.Split;
import org.javasimon.Stopwatch;

public class Test3 {
	public static void main(String[] args) {
		Stopwatch stopwatch = SimonManager.getStopwatch(Test3.class.getName());
		Thread t = new Thread(new MyRunner());
		t.setDaemon(true);
		t.start();

		for (int i = 0; i < 100; i++) {
			test();
		}
	}
	private static void test() {
		Split split = SimonManager.getStopwatch(Test3.class.getName()).start();
		long random = (long) (Math.random() * 1000);
		try {
			Thread.sleep(random);
		} catch (InterruptedException ex) {
			ex.printStackTrace();
		}
		split.stop();
	}
}

class MyRunner implements Runnable {
	public void run() {
		while (true) {
			Stopwatch stopwatch = SimonManager.getStopwatch(Test3.class.getName());
			System.out.println(stopwatch);
			System.out.println(stopwatch.sample());
			try {
				Thread.sleep(10 * 1000);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
	}
}
